package flc.ast.activity;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;

import android.os.Bundle;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;

import java.util.ArrayList;
import java.util.List;

import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.adapter.TemplateAdapter;
import flc.ast.databinding.ActivityCardTemplateBinding;
import stark.common.basic.event.EventStatProxy;

public class CardTemplateActivity extends BaseAc<ActivityCardTemplateBinding> {

    private TemplateAdapter templateAdapter;

    @Override
    protected int onCreate() {
        return R.layout.activity_card_template;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(this, mDataBinding.event1Container);

        mDataBinding.ivCardTemplateBack.setOnClickListener(v -> onBackPressed());

        mDataBinding.rvTemplateList.setLayoutManager(new GridLayoutManager(mContext, 2));
        templateAdapter = new TemplateAdapter();
        mDataBinding.rvTemplateList.setAdapter(templateAdapter);
        templateAdapter.addChildClickViewIds(R.id.ivTemplateItemPreview);
        templateAdapter.addChildClickViewIds(R.id.ivTemplateItemUse);
        templateAdapter.setOnItemChildClickListener(this);
    }

    @Override
    public void onItemChildClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position) {
        switch (view.getId()) {
            case R.id.ivTemplateItemPreview://预览
                TemplatePreviewActivity.img = templateAdapter.getItem(position);
                TemplatePreviewActivity.position = position;
                startActivity(TemplatePreviewActivity.class);
                break;
            case R.id.ivTemplateItemUse://使用
                MakeCardActivity.position = position;
                startActivity(MakeCardActivity.class);
                break;
        }
    }

    @Override
    protected void initData() {
        List<Integer> listTemplate = new ArrayList<>();
        listTemplate.add(R.drawable.mb1);
        listTemplate.add(R.drawable.mb2);
        listTemplate.add(R.drawable.mb3);
        listTemplate.add(R.drawable.mb4);
        listTemplate.add(R.drawable.mb5);
        listTemplate.add(R.drawable.mb6);
        listTemplate.add(R.drawable.mb7);
        listTemplate.add(R.drawable.mb8);
        listTemplate.add(R.drawable.mb9);
        templateAdapter.setList(listTemplate);
    }
}